<?php
/**
 * 记录用户操作日志
 *
 * @author YeFng
 */
class log {
    /**
     * 记录
     * @param type $type mod
     * @param type $msg
     * @param type $item
     * @return boolean
     */
    static function write($type, $msg, $item=null)
	{	
		$file = BACKUP_DIR .'log/'. date('Ym') .'.csv';
		if (!is_dir(dirname($file)))
			return;
        
        if (isset($item))
            $msg = $msg .' -> '. $item;
		$data = array(
			'userID'=> intval(YF_f::$login_user_id),
            'type' => $type,
			'info'  => $msg,
			'ip'	=> getIP(),
			'time'	=> date('Ymd His'));
		$fp = fopen($file, "a");
        if (!$fp)
            YF_f::error (lang::g('write log failed'), 0);
		fputcsv($fp, $data);
		fclose($fp);
	}    
}
